<?php
class BaseModel extends CI_Model
{

    function CommonModel()
    {
        parent::__construct();
    }


    // 统计符合条件的记录数
    public function count_record($table,$conditions = null,$where=null)
    {
        if (!empty($conditions))
        {
            $this->db->or_like($conditions);
        }

        if (!empty($where))
        {
            $this->db->where($where);
        }

        if(!empty($wherein))
        {
            $this->db->where_in($wherein);
        }

        $this->db->from($table);
        return $this->db->count_all_results();
    }

    /**
     *  返回符合条件的记录集
     *
     * @var array   $conditions
     * @var array   $fields
     * @var string  $order
     * @var int     $page
     * @var int     $pagesize
     * @return array
     */

    public function find_All($table,$conditions = null, $where=null,$Fields = null, $order = null, $page = 0, $pagesize = 10)
    {
        if(!empty($conditions))
        {
            $this->db->or_like($conditions);
        }

        if (!empty($where))
        {
            $this->db->where($where);
        }

        if (!empty($Fields))
        {
            $this->db->select($Fields);
        }

        if (!empty($order))
        {
            for($i=0,$j=count($order);$i<$j;$i++)
            {
                $this->db->order_by($order[$i]);
            }
        }

        if(!empty($wherein))
        {
            $this->db->where_in($wherein);
        }

        $this->db->limit($pagesize, $page);
        $query = $this->db->get($table);
        return $query->result_array();
    }






}

?>